const wsedz = require('svg-captcha')
const koabed = require('koa-bodyparser');
const cgy = require('../public/user.json')[0];

const router = require('koa-router')()

// 登录时所需的路由
router.post('/login',koabed(),ets=>{
    const username = ets.request.body.username;
    const password = ets.request.body.password;
    if(username === cgy.username && password === cgy.pwd){
        ets.body={
            'code':299,
            'msg':'登录成功',
            'data':cgy
        }
    }else{
        ets.body={
            'code':300,
            'msg':'登录失败',
            'data':cgy
        }
    }
})



router.get('/captcha', async (ets, next) => { 
    const captcha = wsedz.create();
    const answer = captcha.text.toLowerCase();
    console.log(answer);
    ets.type = 'svg'; 

    ets.body = {'data':captcha.data,'wsedz':answer} 
})



module.exports = router